package office.action.sale;

import java.util.List;

import office.action.sale.form.RivalConditionForm;
import office.action.sale.form.RivalForm;
import office.action.sale.wrapper.RivalWrapper;
import office.service.sale.IRivalService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;

/**
 * 
 * 竞争对手信息
 * 
 * @author ZhangYQ
 * 
 */
public class RivalAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private IRivalService rivalService;
	private Page page; // 分页信息
	private List<RivalWrapper> wrapperList;
	private RivalForm form;
	private RivalConditionForm condition;
	private String id;

	/**
	 * 获取所有的产品明细以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllRival() throws Exception {
		page = rivalService.getPageInfo(condition);
		wrapperList = rivalService.findAllRival(condition,page);
//		if(condition!=null){
//			return "listRivalByPage";
//		}
		return "findAllRival";
	}

	/**
	 * 初始化编辑竞争对手页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditRival() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = rivalService.getById(id);
		}
		return "gotoEditRival";
	}

	/**
	 * 编辑竞争对手
	 * @return
	 * @throws Exception
	 */
	public String editRival() throws Exception {
		try {
			
			if (null == form.getId() || ("").equals(form.getId())) {
				form.setCreateUser((String)getUserMap().get("userId"));
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}
			rivalService.editRival(form);

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * <br/>
	 * 方法描述:分页条件查询产品结构
	 * @return
	 * @throws Exception
	 */
	public String listRivalByPage() throws Exception {
		try {
			wrapperList = rivalService.findAllRival(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "findAllRival";
	}

	/**
	 * 初始化产品结构列表操作菜单
	 * @throws Exception
	 */

	public String gotoRivalMenu() throws Exception {
		return "gotoRivalMenu";
	}

	/**
	 * 跳转到竞争对手删除确认页面
	 */
	public String gotoDeleteRival(){
		return "gotoDeleteRival";
	}
	
	/**
	 * 删除竞争对手
	 * @return
	 * @throws Exception
	 */
	public String delRival() throws Exception {
		try {
			rivalService.delRivalById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public IRivalService getRivalService() {
		return rivalService;
	}

	public void setRivalService(IRivalService rivalService) {
		this.rivalService = rivalService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<RivalWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<RivalWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public RivalForm getForm() {
		return form;
	}

	public void setForm(RivalForm form) {
		this.form = form;
	}

	public RivalConditionForm getCondition() {
		return condition;
	}

	public void setCondition(RivalConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
}
